﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;

namespace ERP.Classes
{
    public class cs_hmr_nhom_nguoi_dungInfo
    {
        private int _id_nhomnguoidung;
        private string _tennhom;
        private string _mota;

        
        public cs_hmr_nhom_nguoi_dungInfo()
        {
            this._id_nhomnguoidung = 0;
            this._tennhom = " ";
            this._mota = " ";

        }
        public int id_nhomnguoidung
        {
            get
            {
                return this._id_nhomnguoidung;
            }
            set
            {
                this._id_nhomnguoidung = value;
            }
        }
        public string tennhom
        {
            get
            {
                return this._tennhom;
            }
            set
            {
                this._tennhom = value;
            }
        }
        public string mota
        {
            get
            {
                return this._mota;
            }
            set
            {
                this._mota = value;
            }
        }

        public int ExcuteStoreProcedure(string storeProcedure, int option)
        {
            string[] paraName = new string[4];
            paraName[0] = "@id_nhomnguoidung";
            paraName[1] = "@tennhom";
            paraName[2] = "@mota";
            paraName[3] = "@option";
            object[] paraValue = new object[4];
            paraValue[0] = this._id_nhomnguoidung;
            paraValue[1] = this._tennhom;
            paraValue[2] = this._mota;
            paraValue[3] = option;
            csCSDL csdl = new csCSDL();
            int i = 0;
            i = csdl.CreateParameters(paraName, 4, paraValue);
            return csdl.ExcuteStoreProcedure(storeProcedure);
        }
        public void KetDulieuVaoListview(ListView myList)
        {
            csListView list = new csListView();
            string[] fields = new string[3];
            fields[0] = "id_nhomnguoidung";
            fields[1] = "tennhom";
            fields[2] = "mota";
            list.KetDulieu(myList, "HMR_Nhom_Nguoi_Dung", "", fields);
        }
        public int ExcuteProcedure(int option)
        {
            return this.ExcuteStoreProcedure("Proc_HMR_Nhom_Nguoi_Dung", option);
        }

        public void ShowDataInCombo(ComboBox cbo, string condition)
        {
            csComboBox cb = new csComboBox("tennhom", "id_nhomnguoidung");
            cb.KetDuLieu(cbo, "HMR_Nhom_Nguoi_Dung", condition);
        }

        public int ShowDataGrid(DataGrid datagrid, string condition)
        {
            csDataGrid grid = new csDataGrid();

            string[] header = new string[3];
            header[0] = "id_nhomnguoidung";
            header[1] = "tennhom";
            header[2] = "mota";

            string[] mappingname = new string[3];
            mappingname[0] = "id_nhomnguoidung";
            mappingname[1] = "tennhom";
            mappingname[2] = "mota";

            int[] colwidth = new int[3];
            colwidth[0] = 12;
            colwidth[1] = 1200;
            colwidth[2] = 1200;
            csCSDL csdl = new csCSDL();
            return grid.CreateTableStyle("HMR_Nhom_Nguoi_Dung", datagrid, csdl.OpenTable("HMR_Nhom_Nguoi_Dung", condition), header, mappingname, colwidth, 3);
        }
        public int Get_Info()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                ds = csdl.OpenTable("HMR_Nhom_Nguoi_Dung", "id_nhomnguoidung = " + this._id_nhomnguoidung);
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return 0;
                }
                this._id_nhomnguoidung = Convert.ToInt32(ds.Tables[0].Rows[0]["id_nhomnguoidung"].ToString().Trim());
                this._tennhom = ds.Tables[0].Rows[0]["tennhom"].ToString().Trim();
                this._mota = ds.Tables[0].Rows[0]["mota"].ToString().Trim();
                return 1;
            }
            catch
            {
                return -1;
            }
        }

        public DataSet Get_List()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                string sql = "select id_nhomnguoidung, rtrim(tennhom) as tennhom, rtrim(mota) as mota "
                        + " from HMR_Nhom_Nguoi_Dung";
                ds = csdl.SelecSQL(sql);
                
                return ds;
            }
            catch
            {
                return null;
            }
        }
    }
}
